import { Controller, Post, Body } from '@nestjs/common'
import { AuthService } from './auth.service'
import { RegisterDto } from './dto/registerDto'
import { LoginDto } from './dto/loginDto'
import { SvgCaptchaService } from 'src/svg-captcha/svg-captcha.service'

@Controller('auth')
export class AuthController {
   constructor(private readonly authService: AuthService, private captha: SvgCaptchaService) {}

   @Post('/login')
   async login(@Body() loginDto: LoginDto) {
      await this.captha.check(loginDto.capthaKey, loginDto.capthaValue)
      return this.authService.login(loginDto)
   }

   @Post('/register')
   async register(@Body() registerDto: RegisterDto) {
      await this.captha.check(registerDto.capthaKey, registerDto.capthaValue)
      return this.authService.register(registerDto)
   }
}
